/**
 * 动态插入css
 */

export const loadStyle = url => {
  const link = document.createElement('link')
  link.type = 'text/css'
  link.rel = 'stylesheet'
  link.href = url
  const head = document.getElementsByTagName('head')[0]
  head.appendChild(link)
}
/**
 * 设置浏览器头部标题
 */
export const setTitle = function(title) {
 // title = title ? `${title}` : '大病理赔'
  // window.document.title = title + '-大病理赔'
  window.document.title = '大病理赔系统'
}

// 关闭当前页面跳转至指定页面
export function closePageTo(store, route, router, path) {
  let currentView = store.state.tagsView.visitedViews[0]
  let visitedViews = store.state.tagsView.visitedViews;
  for (const view of visitedViews) {
    let currentViewPath = view.path;
    if(currentViewPath.indexOf('?') !=-1){
      currentViewPath = currentViewPath.substring(0,currentViewPath.lastIndexOf("?"));
    }
    if (currentViewPath === route.path) {
        currentView = view;
        break
    }
  } 
	store.dispatch('delVisitedViews', currentView).then((views) => {
      if(path){
          router.push({name:''+path +''})
      }else{
          const latestView = views.slice(-1)[0]
          if (latestView) {
            router.push(latestView.path)
          } else {
          router.push('/')
          }
      }
  })
}

// 判断字符串为空
export function isEmptyStr(str){
    if(str == undefined || str == null || str == ''){
      return true;
    }
    return false;
}
// 判断字符串不为空
export function isNotEmptyStr(){
    if(str != undefined && str != null && str != ''){
      return true;
    }
    return false;
}